package com.usermanage.controller;

import com.usermanage.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by  on 2018/9/10
 */
@Slf4j
@RestController
public class FreeMarkerController {


    @RequestMapping("/freemarker")
    public ModelAndView freemarker() throws Exception{
        Map<String, Object> map = new HashMap<>();
        map.put("name", "Joe");
        map.put("sex", 1);    //sex:性别，1：男；0：女；

        ModelAndView mv = new ModelAndView();
        mv.addObject("name","joe");

        // 模拟数据
        List<Map<String, Object>> friends = new ArrayList<Map<String, Object>>();
        Map<String, Object> friend = new HashMap<String, Object>();
        friend.put("name", "xbq");
        friend.put("age", 22);
        friends.add(friend);
        friend = new HashMap<String, Object>();
        friend.put("name", "July");
        friend.put("age", 18);
        friends.add(friend);
        mv.addObject("list1",friends);


        String json = "[\n" +
                "    {\n" +
                "        \"mCname\": \"框架应用管理\",\n" +
                "        \"mIcon\": \"fa fa-square-o\",\n" +
                "        \"mAppid\": 1,\n" +
                "        \"mIsclose\": 0,\n" +
                "        \"mIssys\": 1,\n" +
                "        \"mUrl\": \"\",\n" +
                "        \"children\": [\n" +
                "            {\n" +
                "                \"mCname\": \"模块管理\",\n" +
                "                \"mIcon\": \"fa fa-cube\",\n" +
                "                \"mAppid\": 1,\n" +
                "                \"mIsclose\": 0,\n" +
                "                \"mIssys\": 1,\n" +
                "                \"mUrl\": \"AppMgr/ModuleManager/default.aspx\",\n" +
                "                \"children\": [],\n" +
                "                \"mOrderlevel\": \"0001\",\n" +
                "                \"mParentName\": \"框架应用管理\",\n" +
                "                \"mParentid\": 1,\n" +
                "                \"moduleid\": 2,\n" +
                "                \"mModulecode\": \"S00M00\",\n" +
                "                \"aAppName\": \"框架应用管理\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"mCname\": \"配置管理\",\n" +
                "                \"mIcon\": \"fa fa-cog\",\n" +
                "                \"mAppid\": 1,\n" +
                "                \"mIsclose\": 0,\n" +
                "                \"mIssys\": 1,\n" +
                "                \"mUrl\": \"AppMgr/ConfigManager/default.aspx\",\n" +
                "                \"children\": [],\n" +
                "                \"mOrderlevel\": \"0002\",\n" +
                "                \"mParentName\": \"框架应用管理\",\n" +
                "                \"mParentid\": 1,\n" +
                "                \"moduleid\": 3,\n" +
                "                \"mModulecode\": \"S00M01\",\n" +
                "                \"aAppName\": \"框架应用管理\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"mCname\": \"应用字段设置\",\n" +
                "                \"mIcon\": \"fa fa-key\",\n" +
                "                \"mAppid\": 1,\n" +
                "                \"mIsclose\": 0,\n" +
                "                \"mIssys\": 1,\n" +
                "                \"mUrl\": \"AppMgr/FieldManager/default.aspx\",\n" +
                "                \"children\": [],\n" +
                "                \"mOrderlevel\": \"0003\",\n" +
                "                \"mParentName\": \"框架应用管理\",\n" +
                "                \"mParentid\": 1,\n" +
                "                \"moduleid\": 4,\n" +
                "                \"mModulecode\": \"S00M02\",\n" +
                "                \"aAppName\": \"框架应用管理\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"mCname\": \"系统异常日志\",\n" +
                "                \"mIcon\": \"fa fa-file-pdf-o\",\n" +
                "                \"mAppid\": 1,\n" +
                "                \"mIsclose\": 0,\n" +
                "                \"mIssys\": 1,\n" +
                "                \"mUrl\": \"AppMgr/SystemErrorLog/default.aspx\",\n" +
                "                \"children\": [],\n" +
                "                \"mOrderlevel\": \"0004\",\n" +
                "                \"mParentName\": \"框架应用管理\",\n" +
                "                \"mParentid\": 1,\n" +
                "                \"moduleid\": 5,\n" +
                "                \"mModulecode\": \"S00M03\",\n" +
                "                \"aAppName\": \"框架应用管理\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"mCname\": \"事件日志\",\n" +
                "                \"mIcon\": \"fa fa-file-zip-o\",\n" +
                "                \"mAppid\": 1,\n" +
                "                \"mIsclose\": 0,\n" +
                "                \"mIssys\": 1,\n" +
                "                \"mUrl\": \"AppMgr/EventLog/default.aspx\",\n" +
                "                \"children\": [],\n" +
                "                \"mOrderlevel\": \"0005\",\n" +
                "                \"mParentName\": \"框架应用管理\",\n" +
                "                \"mParentid\": 1,\n" +
                "                \"moduleid\": 6,\n" +
                "                \"mModulecode\": \"S00M04\",\n" +
                "                \"aAppName\": \"框架应用管理\"\n" +
                "            }\n" +
                "        ],\n" +
                "        \"mOrderlevel\": \"0000\",\n" +
                "        \"mParentid\": 0,\n" +
                "        \"moduleid\": 1,\n" +
                "        \"mModulecode\": \"S00\",\n" +
                "        \"aAppName\": \"框架应用管理\"\n" +
                "    },\n" +
                "    {\n" +
                "        \"mCname\": \"系统管理\",\n" +
                "        \"mIcon\": \"fa fa-cogs\",\n" +
                "        \"mAppid\": 2,\n" +
                "        \"mIsclose\": 0,\n" +
                "        \"mIssys\": 0,\n" +
                "        \"mUrl\": \"\",\n" +
                "        \"children\": [\n" +
                "            {\n" +
                "                \"mCname\": \"行政区管理\",\n" +
                "                \"mIcon\": \"fa fa-circle\",\n" +
                "                \"mAppid\": 2,\n" +
                "                \"mIsclose\": 0,\n" +
                "                \"mIssys\": 0,\n" +
                "                \"mUrl\": \"SysMgr/AreaManager/default.aspx\",\n" +
                "                \"children\": [],\n" +
                "                \"mOrderlevel\": \"0001\",\n" +
                "                \"mParentName\": \"系统管理\",\n" +
                "                \"mParentid\": 7,\n" +
                "                \"moduleid\": 8,\n" +
                "                \"mModulecode\": \"S10M01\",\n" +
                "                \"aAppName\": \"应用系统管理\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"mCname\": \"组织机构管理\",\n" +
                "                \"mIcon\": \"fa fa-tree\",\n" +
                "                \"mAppid\": 2,\n" +
                "                \"mIsclose\": 0,\n" +
                "                \"mIssys\": 0,\n" +
                "                \"mUrl\": \"SysMgr/CompanyManager/default.aspx\",\n" +
                "                \"children\": [],\n" +
                "                \"mOrderlevel\": \"0002\",\n" +
                "                \"mParentName\": \"系统管理\",\n" +
                "                \"mParentid\": 7,\n" +
                "                \"moduleid\": 9,\n" +
                "                \"mModulecode\": \"S10M02\",\n" +
                "                \"aAppName\": \"应用系统管理\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"mCname\": \"角色权限管理\",\n" +
                "                \"mIcon\": \"fa fa-user-secret\",\n" +
                "                \"mAppid\": 2,\n" +
                "                \"mIsclose\": 0,\n" +
                "                \"mIssys\": 0,\n" +
                "                \"mUrl\": \"SysMgr/RoleManager/default.aspx\",\n" +
                "                \"children\": [],\n" +
                "                \"mOrderlevel\": \"0003\",\n" +
                "                \"mParentName\": \"系统管理\",\n" +
                "                \"mParentid\": 7,\n" +
                "                \"moduleid\": 10,\n" +
                "                \"mModulecode\": \"S10M03\",\n" +
                "                \"aAppName\": \"应用系统管理\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"mCname\": \"用户管理\",\n" +
                "                \"mIcon\": \"fa fa-users\",\n" +
                "                \"mAppid\": 2,\n" +
                "                \"mIsclose\": 0,\n" +
                "                \"mIssys\": 0,\n" +
                "                \"mUrl\": \"SysMgr/UserManager/default.aspx\",\n" +
                "                \"children\": [],\n" +
                "                \"mOrderlevel\": \"0004\",\n" +
                "                \"mParentName\": \"系统管理\",\n" +
                "                \"mParentid\": 7,\n" +
                "                \"moduleid\": 11,\n" +
                "                \"mModulecode\": \"S10M04\",\n" +
                "                \"aAppName\": \"应用系统管理\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"mCname\": \"数据字典\",\n" +
                "                \"mIcon\": \"fa fa-leaf\",\n" +
                "                \"mAppid\": 2,\n" +
                "                \"mIsclose\": 0,\n" +
                "                \"mIssys\": 0,\n" +
                "                \"mUrl\": \"SysMgr/FieldValueManager/default.aspx\",\n" +
                "                \"children\": [],\n" +
                "                \"mOrderlevel\": \"0005\",\n" +
                "                \"mParentName\": \"系统管理\",\n" +
                "                \"mParentid\": 7,\n" +
                "                \"moduleid\": 12,\n" +
                "                \"mModulecode\": \"S10M05\",\n" +
                "                \"aAppName\": \"应用系统管理\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"mCname\": \"在线用户列表\",\n" +
                "                \"mIcon\": \"fa fa-user\",\n" +
                "                \"mAppid\": 2,\n" +
                "                \"mIsclose\": 0,\n" +
                "                \"mIssys\": 0,\n" +
                "                \"mUrl\": \"SysMgr/OnlineUser/default.aspx\",\n" +
                "                \"children\": [],\n" +
                "                \"mOrderlevel\": \"0009\",\n" +
                "                \"mParentName\": \"系统管理\",\n" +
                "                \"mParentid\": 7,\n" +
                "                \"moduleid\": 16,\n" +
                "                \"mModulecode\": \"S10M09\",\n" +
                "                \"aAppName\": \"应用系统管理\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"mCname\": \"系统设置\",\n" +
                "                \"mIcon\": \"fa fa-cog\",\n" +
                "                \"mAppid\": 2,\n" +
                "                \"mIsclose\": 0,\n" +
                "                \"mIssys\": 0,\n" +
                "                \"mUrl\": \"\",\n" +
                "                \"children\": [\n" +
                "                    {\n" +
                "                        \"mCname\": \"事件日志查询\",\n" +
                "                        \"mIcon\": \"fa fa-search-minus\",\n" +
                "                        \"mAppid\": 2,\n" +
                "                        \"mIsclose\": 0,\n" +
                "                        \"mIssys\": 0,\n" +
                "                        \"mUrl\": \"SysMgr/EventManager/default.aspx\",\n" +
                "                        \"children\": [],\n" +
                "                        \"mOrderlevel\": \"0006\",\n" +
                "                        \"mParentName\": \"系统设置\",\n" +
                "                        \"mParentid\": 43,\n" +
                "                        \"moduleid\": 13,\n" +
                "                        \"mModulecode\": \"S10M06\",\n" +
                "                        \"aAppName\": \"应用系统管理\"\n" +
                "                    },\n" +
                "                    {\n" +
                "                        \"mCname\": \"系统参数管理\",\n" +
                "                        \"mIcon\": \"fa fa-square\",\n" +
                "                        \"mAppid\": 2,\n" +
                "                        \"mIsclose\": 0,\n" +
                "                        \"mIssys\": 0,\n" +
                "                        \"mUrl\": \"SysMgr/SystemParam/default.aspx\",\n" +
                "                        \"children\": [],\n" +
                "                        \"mOrderlevel\": \"0007\",\n" +
                "                        \"mParentName\": \"系统设置\",\n" +
                "                        \"mParentid\": 43,\n" +
                "                        \"moduleid\": 14,\n" +
                "                        \"mModulecode\": \"S10M07\",\n" +
                "                        \"aAppName\": \"应用系统管理\"\n" +
                "                    },\n" +
                "                    {\n" +
                "                        \"mCname\": \"系统维护\",\n" +
                "                        \"mIcon\": \"fa fa-shield\",\n" +
                "                        \"mAppid\": 2,\n" +
                "                        \"mIsclose\": 0,\n" +
                "                        \"mIssys\": 0,\n" +
                "                        \"mUrl\": \"SysMgr/SystemState/default.aspx\",\n" +
                "                        \"children\": [],\n" +
                "                        \"mOrderlevel\": \"0008\",\n" +
                "                        \"mParentName\": \"系统设置\",\n" +
                "                        \"mParentid\": 43,\n" +
                "                        \"moduleid\": 15,\n" +
                "                        \"mModulecode\": \"S10M08\",\n" +
                "                        \"aAppName\": \"应用系统管理\"\n" +
                "                    }\n" +
                "                ],\n" +
                "                \"mOrderlevel\": \"0010\",\n" +
                "                \"mParentName\": \"系统管理\",\n" +
                "                \"mParentid\": 7,\n" +
                "                \"moduleid\": 43,\n" +
                "                \"mModulecode\": \"S10M10\",\n" +
                "                \"aAppName\": \"应用系统管理\"\n" +
                "            }\n" +
                "        ],\n" +
                "        \"mOrderlevel\": \"0000\",\n" +
                "        \"mParentid\": 0,\n" +
                "        \"moduleid\": 7,\n" +
                "        \"mModulecode\": \"S10\",\n" +
                "        \"aAppName\": \"应用系统管理\"\n" +
                "    },\n" +
                "    {\n" +
                "        \"mCname\": \"查询&报表统计\",\n" +
                "        \"mIcon\": \"\",\n" +
                "        \"mAppid\": 3,\n" +
                "        \"mIsclose\": 0,\n" +
                "        \"mIssys\": 0,\n" +
                "        \"mUrl\": \"\",\n" +
                "        \"children\": [\n" +
                "            {\n" +
                "                \"mCname\": \"快递单查询\",\n" +
                "                \"mIcon\": \"\",\n" +
                "                \"mAppid\": 3,\n" +
                "                \"mIsclose\": 0,\n" +
                "                \"mIssys\": 0,\n" +
                "                \"mUrl\": \"ExpressMgr/ExpDocQuery/default.aspx\",\n" +
                "                \"children\": [],\n" +
                "                \"mOrderlevel\": \"0501\",\n" +
                "                \"mParentName\": \"查询&报表统计\",\n" +
                "                \"mParentid\": 22,\n" +
                "                \"moduleid\": 35,\n" +
                "                \"mModulecode\": \"S36M01\",\n" +
                "                \"aAppName\": \"物流快递管理系统\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"mCname\": \"快递营收统计\",\n" +
                "                \"mIcon\": \"\",\n" +
                "                \"mAppid\": 3,\n" +
                "                \"mIsclose\": 0,\n" +
                "                \"mIssys\": 0,\n" +
                "                \"mUrl\": \"ExpressMgr/ExpIncomeStat/default.aspx\",\n" +
                "                \"children\": [],\n" +
                "                \"mOrderlevel\": \"0502\",\n" +
                "                \"mParentName\": \"查询&报表统计\",\n" +
                "                \"mParentid\": 22,\n" +
                "                \"moduleid\": 36,\n" +
                "                \"mModulecode\": \"S36M02\",\n" +
                "                \"aAppName\": \"物流快递管理系统\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"mCname\": \"快递业务流量分析\",\n" +
                "                \"mIcon\": \"\",\n" +
                "                \"mAppid\": 3,\n" +
                "                \"mIsclose\": 0,\n" +
                "                \"mIssys\": 0,\n" +
                "                \"mUrl\": \"ExpressMgr/ExpDataAnalysis/default.aspx\",\n" +
                "                \"children\": [],\n" +
                "                \"mOrderlevel\": \"0503\",\n" +
                "                \"mParentName\": \"查询&报表统计\",\n" +
                "                \"mParentid\": 22,\n" +
                "                \"moduleid\": 37,\n" +
                "                \"mModulecode\": \"S36M03\",\n" +
                "                \"aAppName\": \"物流快递管理系统\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"mCname\": \"快递业务报表\",\n" +
                "                \"mIcon\": \"\",\n" +
                "                \"mAppid\": 3,\n" +
                "                \"mIsclose\": 0,\n" +
                "                \"mIssys\": 0,\n" +
                "                \"mUrl\": \"ExpressMgr/ExpCustomRpt/default.aspx\",\n" +
                "                \"children\": [],\n" +
                "                \"mOrderlevel\": \"0504\",\n" +
                "                \"mParentName\": \"查询&报表统计\",\n" +
                "                \"mParentid\": 22,\n" +
                "                \"moduleid\": 38,\n" +
                "                \"mModulecode\": \"S36M04\",\n" +
                "                \"aAppName\": \"物流快递管理系统\"\n" +
                "            }\n" +
                "        ],\n" +
                "        \"mOrderlevel\": \"0500\",\n" +
                "        \"mParentid\": 0,\n" +
                "        \"moduleid\": 22,\n" +
                "        \"mModulecode\": \"S36\",\n" +
                "        \"aAppName\": \"物流快递管理系统\"\n" +
                "    }\n" +
                "]";
        List list2 = StringUtil.JsonToList(json);




        //select
        List list3 = new ArrayList<>();
        Map map1 = new HashMap();
        map1.put("id",1);
        map1.put("name","select1");
        Map map2 = new HashMap();
        map2.put("id",2);
        map2.put("name","select2");
        Map map3 = new HashMap();
        map3.put("id",3);
        map3.put("name","select3");
        Map map4 = new HashMap();
        map4.put("id",4);
        map4.put("name","select4");
        list3.add(map1);
        list3.add(map2);
        list3.add(map3);
        list3.add(map4);
        mv.addObject("dto",list2);
        mv.addObject("selectList",list3);
        mv.setViewName("/freemarker/freemarker");
        return mv;
    }


    @RequestMapping("/test")
    public ModelAndView freemarker1() throws Exception{
        ModelAndView mv = new ModelAndView();
        mv.setViewName("/freemarker/group/index");
        return mv;
    }
}
